package com.codedancer.campus.client.api.commentReport;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.api.commentReport.ro.CommentReportAddRo;
import com.codedancer.campus.client.service.ICommentReportService;
import com.codedancer.campus.client.service.bo.commentReport.CommentReportAddBo;
import com.codedancer.campus.common.anno.Limit;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "评论举报api", description = "评论举报api", tags = "评论举报api")
@RequestMapping("/api/comment-report")
public class CommentReportApi extends BaseApi {

  @Autowired
  private ICommentReportService commentReportService;

  @PostMapping("/add")
  @ApiOperation("新增举报")
  @Limit(key = "COMMENT_REPORT", permitsPerSecond = 2, timeout = 1000, msg = "系统繁忙，请稍后再试！")
  public ApiResponse<Void> add(
      @RequestBody @Valid @ApiParam(value = "评论举报添加Ro", required = true)
      CommentReportAddRo commentReportAddRo) {
    CommentReportAddBo commentReportAddBo = BeanUtil.copyProperties(commentReportAddRo,
        CommentReportAddBo.class);
    commentReportAddBo.setCurrentUserUuid(currentLoginUuid());
    commentReportService.add(commentReportAddBo);
    return success();
  }
}
